package com.production.CoursePlatform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.production.CoursePlatform.entity.Submission;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SubmissionMapper extends BaseMapper<Submission> {

    // 无需 shID 来创建新记录
    @Insert("INSERT INTO submission (cts_id, ah_id, submit_time, submit_content, attachment) " +
            "VALUES (#{ctsID}, #{ahID}, #{submitTime}, #{submitContent}, #{attachment})")
    int insertWithoutShID(Submission submission);

    // 按照 ahID 查找
    @Select("SELECT * FROM submission WHERE ah_id = #{ahID}")
    List<Submission> selectByAhID(int ahID);

    // 删除
    @Delete("DELETE FROM submission WHERE sh_id = #{shID}")
    int deleteByShID(int shID);

    // 更新
    @Update("UPDATE submission SET cts_id = #{ctsID}, ah_id = #{ahID}, submit_time = #{submitTime}, " +
            "submit_content = #{submitContent}, attachment = #{attachment} WHERE sh_id = #{shID}")
    int updateSubmission(Submission submission);
}
